﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Web;
using Dataglot;
using Dataglot.CrossDb;

namespace SampleApplication.Code
{
    public class CatBreeds:ISupportId
    {
        
        /// <summary>
        /// A short string
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// A date and possibly time
        /// </summary>
        public DateTime DateCreated { get; set; }

        /// <summary>
        /// Money
        /// </summary>
        public Decimal Price { get; set; }

        /// <summary>
        /// Some number, possibly an enum
        /// </summary>
        public int Cuteness { get; set; }

        /// <summary>
        /// Some long text
        /// </summary>
        public string Description { get; set; }

        public long Id { get; set; }

        public void ValidateRequirements()
        {
            //throw new NotImplementedException();
        }
    }

    public class SampleController:TableController<CatBreeds>
    {
        //SqlCompactCats
        public SampleController():
            base(new DataFactory(
                new FeatureSupportInfo()
                {
                    Brand = DbBrand.SqlCompact4,
                    SupportsIdentityColumn = true
                    //,oleDbProvider = ""
                }, 
                
                "SqlCompactCats"), null, null)
        {
            Configure();
        }

        private void Configure()
        {
            tableName = "CatBreeds";

            columns = new Dictionary<string, DbType>
                          {
                              {"Id", DbType.Int32},
                              {"Name", DbType.String},
                              {"DateCreated", DbType.String},
                              {"Price", DbType.Decimal},
                              {"Cuteness", DbType.Int32},
                              {"Description", DbType.String}
                          };
        }

        public SampleController(DataFactory targetFactory, DbConnection connection, DbTransaction transaction)
            : base(targetFactory,  connection,  transaction)
        {
            Configure();
        }
        public override CatBreeds Select(long id)
        {
            return base.ProcessSelect(id);
        }

        public override bool Exists(long id)
        {
            return base.ProcessExists(id);
        }

        public override List<CatBreeds> SelectList(int from, int to)
        {
            return base.ProcessSelectList(from,to);
        }

        public override CatBreeds Insert(CatBreeds setting)
        {
            return base.ProcessInsert(setting);
        }

        public override CatBreeds Update(CatBreeds setting)
        {
            return base.ProcessUpdate(setting);
        }

        public override void Delete(long id)
        {
            base.ProcessDelete(id);
        }

        //Required by ObjectDataSource
        public void Delete(CatBreeds breed)
        {
            base.ProcessDelete(breed.Id);
        }
    }
}